package com.cloud.lawcase.api.mapper;

import java.util.List;

import com.cloud.lawcase.common.driver.SimpleInlangDriver;
import org.apache.ibatis.annotations.*;

import com.cloud.lawcase.api.bean.LawCauseInterfaceSearchCriteria;
import com.cloud.lawcase.api.bean.LawCauseItem;
import com.cloud.lawcase.api.entity.TcDicLawCause;
import com.cloud.lawcase.api.provider.ExotericCauseStackProvider;
import com.cloud.lawcase.api.provider.ExotericLawCausePageProvider;
import com.cloud.lawcase.api.provider.InterfaceLawCausePageProvider;
import com.cloud.lawcase.api.provider.TcDicLawCauseProvider;
import com.cloud.lawcase.common.openapi.OpenApiCauseStackSearchCriteria;
import com.cloud.lawcase.common.openapi.OpenApiLawCauseBean;
import com.cloud.lawcase.common.openapi.OpenApiLawCauseSearchCriteria;
import com.cloud.lawcase.common.openapi.OpenApiLawCauseStackBean;
import com.cloud.lawcase.common.utils.BaseMapperHelper;

public interface TcDicLawCauseMapper extends BaseMapperHelper<TcDicLawCause> {

	@SelectProvider(type = TcDicLawCauseProvider.class, method = "listCauseByLawAndExcute")
	@Results({ @Result(property = "causeId", column = "cause_id", javaType = Long.class),
			@Result(property = "causeCode", column = "cause_code", javaType = String.class),
			@Result(property = "causeName", column = "cause_name", javaType = String.class),
			@Result(property = "excuteTypeId", column = "excute_type_id", javaType = Integer.class),
			@Result(property = "excuteTypeName", column = "excute_type_name", javaType = String.class),
			@Result(property = "isPunish", column = "is_punish", javaType = Integer.class),
			@Result(property = "itemId", column = "item_id", javaType = Long.class),
			@Result(property = "lawId", column = "law_id", javaType = Long.class) })
	List<TcDicLawCause> listCauseByLawAndExcute(@Param("lawId") long lawId, @Param("excuteTypeId") int excuteTypeId);

	@Delete("delete from tc_dic_law_cause where law_id in (select law_id from tc_dic_law where group_id = #{groupId})")
	void deleteByGroupId(@Param("groupId") Long groupId);

	@SelectProvider(type = ExotericLawCausePageProvider.class, method = "listPage")
	@Results({ @Result(property = "causeId", column = "cause_id", javaType = Long.class),
			@Result(property = "causeCode", column = "cause_code", javaType = String.class),
			@Result(property = "causeName", column = "cause_name", javaType = String.class),
			@Result(property = "excuteTypeName", column = "excute_type_name", javaType = String.class),
			@Result(property = "punishItemId", column = "item_id", javaType = Long.class) })
	List<OpenApiLawCauseBean> searchExotericLawCause(OpenApiLawCauseSearchCriteria criteria);

	@SelectProvider(type = ExotericCauseStackProvider.class, method = "listCauseStack")
	@Results({ @Result(property = "situationDesc", column = "situation_desc", javaType = String.class),
			@Result(property = "excuteTypeName", column = "excute_type_name", javaType = String.class),
			@Result(property = "punishId", column = "punish_id", javaType = Long.class) })
	List<OpenApiLawCauseStackBean> listLawCauseStack(OpenApiCauseStackSearchCriteria criteria);

	/**
	 * 
	 * @param criteria
	 * @return
	 */
	@SelectProvider(type = InterfaceLawCausePageProvider.class, method = "searhCausePageInfo")
	@Results({ @Result(property = "lawId", column = "law_id", javaType = Long.class),
			@Result(property = "lawCode", column = "law_code", javaType = String.class),
			@Result(property = "lawTitle", column = "law_title", javaType = String.class),
			@Result(property = "itemId", column = "item_id", javaType = Long.class),
			@Result(property = "itemName", column = "item_name", javaType = String.class),
			@Result(property = "causeId", column = "cause_id", javaType = Long.class),
			@Result(property = "causeCode", column = "cause_code", javaType = String.class),
			@Result(property = "causeName", column = "cause_name", javaType = String.class) })
	List<LawCauseItem> searhCausePageInfo(LawCauseInterfaceSearchCriteria criteria);

	@Select("select cause_id,cause_code from tc_dic_law_cause where cause_code in (#{causeCodes})")
	@Lang(SimpleInlangDriver.class)
	@Results({ @Result(property = "causeId", column = "cause_id", javaType = Long.class),
			@Result(property = "causeCode", column = "cause_code", javaType = String.class) })
	List<LawCauseItem> listCasueIDByCauseCode(@Param("causeCodes") List<String> causeCodes);

}